{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "I0000 00:00:1714828900.120818  263686 gl_context.cc:357] GL version: 2.1 (2.1 INTEL-18.8.6), renderer: Intel HD Graphics 5000 OpenGL Engine\n"
     ]
    }
   ],
   "source": [
    "import cv2\n",
    "import mediapipe as mp\n",
    "from cvzone.HandTrackingModule import HandDetector\n",
    "\n",
    "# hands = mp.solutions.hands\n",
    "# hands_model = hands.Hands(static_image_mode=False, max_num_hands=2, min_detection_confidence=0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "I0000 00:00:1714828968.722472  263686 gl_context.cc:357] GL version: 2.1 (2.1 INTEL-18.8.6), renderer: Intel HD Graphics 5000 OpenGL Engine\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detector = HandDetector(detectionCon=0.8,maxHands=1)\n",
    "\n",
    "video = cv2.VideoCapture(0)  # 0表示打开笔记本的内置摄像头\n",
    "\n",
    "#cv2.namedWindow('video') # 创建窗口\n",
    "\n",
    "while(True):\n",
    "    ret, frame = video.read() # 读取摄像头\n",
    "    if ret:\n",
    "        frame =cv2.flip(frame, 1) # 1水平翻转,0 \n",
    "        #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 转换为灰度图\n",
    "        \n",
    "        hands,img = detector.findHands(frame,flipType=False)\n",
    "\n",
    "        cv2.imshow('video1',img) # 显示一帧图像\n",
    "        key = cv2.waitKey(13) # 每33 ms显示一帧图像\n",
    "        if(key == 27): # 27表示esc键 退出\n",
    "            break\n",
    "    else:\n",
    "        break\n",
    "\n",
    "\n",
    "video.release()  # 释放摄像头\n",
    "cv2.destroyAllWindows() # 销毁窗口\n",
    "cv2.waitKey(1) # "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
